package com.mindskip.xzs.controller.admin;

import com.mindskip.xzs.utility.RestResponse;
import com.mindskip.xzs.domain.vo.admin.dashboard.IndexVO;
import com.mindskip.xzs.service.*;
import com.mindskip.xzs.utility.DateTimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "管理系统首页接口")
@RestController("AdminDashboardController")
@RequestMapping(value = "/api/admin/dashboard")
public class DashboardController {

    private final UserEventLogService userEventLogService;

    private final ExamPaperService examPaperService;

    private final QuestionService questionService;

    private final ExamPaperAnswerService examPaperAnswerService;

    private final ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService;

    public DashboardController(UserEventLogService userEventLogService, ExamPaperService examPaperService, QuestionService questionService, ExamPaperAnswerService examPaperAnswerService, ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService) {
        this.userEventLogService = userEventLogService;
        this.examPaperService = examPaperService;
        this.questionService = questionService;
        this.examPaperAnswerService = examPaperAnswerService;
        this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService;
    }

    @ApiOperation(
            value = "首页信息",
            notes = "展示管理员系统首页的信息",
            httpMethod = "POST"
    )
    @PostMapping (value = "/index")
    public RestResponse<IndexVO> Index() {

        IndexVO indexVO = new IndexVO();

        // 得到试卷总数
        Integer examPaperCount = examPaperService.selectAllCount();
        indexVO.setExamPaperCount(examPaperCount);

        // 得到所有题目数量
        Integer questionCount = questionService.selectAllCount();
        indexVO.setQuestionCount(questionCount);

        // 得到答卷总数
        Integer doExamPaperCount = examPaperAnswerService.selectAllCount();
        indexVO.setDoExamPaperCount(doExamPaperCount);

        // 得到总答题数
        Integer doQuestionCount = examPaperQuestionCustomerAnswerService.selectAllCount();
        indexVO.setDoQuestionCount(doQuestionCount);

        // 得到月活跃度
        List<Integer> mothDayUserActionValue = userEventLogService.selectMonthCount();
        indexVO.setMothDayUserActionValue(mothDayUserActionValue);

        // 得到当前月份从月初到今天每天的答题数量
        List<Integer> mothDayDoExamQuestionValue = examPaperQuestionCustomerAnswerService.selectMonthCount();
        indexVO.setMothDayDoExamQuestionValue(mothDayDoExamQuestionValue);

        // 得到本月天数
        List<String> mothDayText = DateTimeUtil.MothDay();
        indexVO.setMothDayText(mothDayText);

        return RestResponse.ok(indexVO);
    }
}
